import CommonBaseSchema from '#common/base_schema'

export default class extends CommonBaseSchema {
  protected tableName = 'dicts'

  async up() {
    this.schema.createTable(this.tableName, (table) => {
      table.increments()
      table
        .integer('fk_shop_id')
        .notNullable()
        .unsigned()
        .references('shops.id')
        .comment('所属店铺ID')

      table.string('class_name').notNullable().comment('分类名称')
      table.integer('sort').unsigned().defaultTo(1).comment('排序')
      table.string('name', 20).notNullable().comment('字典名称')
      table.string('code', 10).notNullable().comment('唯一代码')
      table.json('extra').nullable().comment('扩展')
      table.tinyint('status').defaultTo(1).unsigned().comment('状态')
      table.string('relation_code', 64).nullable().comment('关联code')
      table.boolean('is_builtin').defaultTo(false).comment('内置')
      table.string('memo', 255).defaultTo('').comment('备注')

      this.defineCommonColumns(table)
      table.comment('字典表')
    })
  }

  async down() {
    this.schema.dropTable(this.tableName)
  }
}
